package com.kolon.business.mngr.client.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.mngr.client.dao.ClientDao;
import com.kolon.framework.constant.Constant;
import com.kolon.framework.file.FileUtil;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mngr.client.controller.ClientDeleteController")
public class ClientDeleteController implements SimpleController {

	@Resource(name="com.kolon.business.mngr.client.dao.ClientDaoImpl")
	private ClientDao clientDao;
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mngr/client/clientDelete.do")
	public ModelAndView controller(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		
		Map<String, String> map = new HashMap<String, String>();
		// 파라미터
		String frfTp = ComUtil.nullChk(request.getParameter("frfTp"));
		// 파일 저장 경로
		String appUploadPath = MsgUtil.getMessage("app.file.path");
		map.put("frfTp", frfTp);
		// 서비스 정보 조회
		Map cntMap = clientDao.getMap(map);
		if (cntMap != null) {
			// 데이터 및 앱 삭제
			FileUtil.dirDelete(new File(appUploadPath + frfTp.toLowerCase()
					+ File.separator + Constant.APP_CNT_NM + File.separator));
			clientDao.delete(map);
		}
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/business/mngr/client/clientModifyForm.do");
		modelAndView.addObject("frfTp", frfTp);
		return modelAndView;
	}
}
